<template>
  <div class="home-view" style="display: flex">
    <!-- 顶部导航栏 -->
    <nav class="navbar">
      <div class="navbar-brand">
        <a class="navbar-item">Logo</a>
      </div>
      <div class="navbar-menu">
        <a href="#" class="navbar-item" @click="navigate('/recommend')" :class="{ active: isActive('/recommend') }">推荐</a>
        <a href="/homepage" class="navbar-item" @click="navigate('/homepage')" :class="{ active: isActive('/homepage') }">主页</a>
        <a href="/community" class="navbar-item" @click="navigate('/community')" :class="{ active: isActive('/community') }">社区主页</a>
        <a href="/article" class="navbar-item" @click="navigate('/article')" :class="{ active: isActive('/article') }">发布文章</a>
        <a href="#" class="navbar-item" @click="navigate('/movie')" :class="{ active: isActive('/movie') }">影视</a>
        <a href="#" class="navbar-item" @click="navigate('/career')" :class="{ active: isActive('/career') }">职场</a>
        <a href="#" class="navbar-item" @click="navigate('/emotion')" :class="{ active: isActive('/emotion') }">情感</a>
        <a href="#" class="navbar-item" @click="navigate('/household')" :class="{ active: isActive('/household') }">家居</a>
        <a href="#" class="navbar-item" @click="navigate('/game')" :class="{ active: isActive('/game') }">游戏</a>
        <a href="#" class="navbar-item" @click="navigate('/travel')" :class="{ active: isActive('/travel') }">旅行</a>
        <a href="#" class="navbar-item" @click="navigate('/fitness')" :class="{ active: isActive('/fitness') }">健身</a>
      </div>
      <div class="search-container" style="margin: 0 40px 0 auto">
        <input type="text" v-model="searchQuery" placeholder="搜索..." class="search-input" />
        <button class="search-button" @click="handleSearch">搜索</button>
      </div>
      <div class="avatar-container">
        <img :src="avatarUrl" alt="Avatar" class="avatar" />
      </div>
    </nav>

    <!-- 主体内容区域 -->
    <el-main style="padding: 0; overflow-y: auto;">
      <router-view />
    </el-main>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

function navigate(path) {
  if (path.startsWith('/')) {
    history.pushState({}, '', path);
    currentPath.value = path;
  }
}

onMounted(() => {
  // 初始化当前路径
  currentPath.value = window.location.pathname;
});
</script>

<style scoped>
.home-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  /* 使用更丰富的渐变色带 */
  background: linear-gradient(90deg, #8e2de2 0%, #8b1ae6 30%, #4a00e0 100%);
  color: white;
  /* 添加圆角 */
  border-radius: 10px;
  /* 添加盒子阴影 */
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  /* 添加文本阴影 */
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
  /* 可选：在高亮或者悬停状态下改变背景颜色 */
  transition: background-color 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* 可选：当鼠标悬停在导航条上时，改变背景颜色 */
.navbar:hover {
  background: linear-gradient(90deg, #8e2de2 0%, #8b1ae6 30%, #5500f0 100%);
  transform: scale(1.02);
}

.navbar-item {
  color: white;
  text-decoration: none;
  margin: 0 1rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  transition: background-color 0.3s ease;
}

.navbar-item.active {
  background-color: rgba(255, 255, 255, 0.2);
}

.navbar-item:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.search-container {
  display: flex;
  align-items: center;
}

.search-input {
  padding: 0.5rem;
  border: none;
  border-radius: 4px 0 0 4px;
  outline: none;
  background-color: rgba(255, 255, 255, 0.7);
  color: #333;
}

.search-button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0 4px 4px 0;
  background-color: #6c5ce7;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.search-button:hover {
  background-color: #7c67f7;
}

.avatar-container {
  position: relative;
  margin-left: 1rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.el-main {
  flex: 1;
  padding: 0;
  overflow-y: auto;
}
</style>